<template>
  <el-dialog title="追加奖金" :close-on-click-modal="false" :visible.sync="visible" append-to-body width="500px">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
      <el-form-item label="奖金池" prop="jjcId">
        <el-select style="width: 100%;" :clearable="true" @change="setLyLx" v-model="dataForm.jjcId" placeholder="请选择奖金池">
          <el-option v-for="item in fpLyList " :key="item.value" :label="item.jjxName +'-'+item.jjxFl+'('+item.jjcYe+'元)'" :value="item.jjcId">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="奖金金额" prop="jjcYe">
        <el-input-number :disabled="false" v-model="dataForm.jjcYe" placeholder="奖金金额" style="width: 100%;"></el-input-number>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
      <el-button @click="visible = false">取消</el-button>
    </span>
  </el-dialog>
</template>
<script>
import {getFplyList, saveJjzj} from '@/api/jiangjin/jiangjinfpjjlydjb'

export default {
  data() {
    return {
      fpLyList: [],
      visible: false,
      canSubmit: false,
      fpId: 0,
      dataForm: {
        jjJe: '',
        jjcId: ''
      },
      dataRule: {
        jjcId: [{
          required: true,
          message: '请选择奖金池',
          trigger: 'blur'
        }],
      },
      cfid:''
    }
  },
  created() {
  },
  methods: {
    csh() {
      this.fpId = 0;
      this.fpLyList = [];
      this.dataForm = {
        jjJe: '',
        jjcId: ''
      };
    },
    init(fpId, jjDeptId,cfid) {
      this.csh();
      this.fpId = fpId;
      this.cfid=cfid
      this.visible = true;
      this.canSubmit = true;
      this.$nextTick(() => {
        getFplyList(jjDeptId, 0).then(response => {
          this.fpLyList = response.data.data;
          console.log(JSON.stringify(this.fpLyList))
        })
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['dataForm'].validate((valid) => {
        // console.log(this.fpId, this.dataForm.jjcId,this.dataForm.jjcYe)
        if (valid) {
          saveJjzj(this.fpId, this.dataForm.jjcId,this.dataForm.jjcYe,this.cfid).then(data => {
            
            this.$notify.success(data.data.msg)
            this.visible = false
             this.$emit('chaifenChild')
          }).catch(() => {
            this.canSubmit = true;
          });
        }
      })
    },
    setLyLx() {
      for (var i = 0; i < this.fpLyList.length; i++) {
        if (this.fpLyList[i].jjcId == this.dataForm.jjcId) {
          this.dataForm.jjcYe = this.fpLyList[i].jjcYe
          break
        }
      }
    }
  }
}

</script>
